package com.example.scrambledpuzzle;

import android.content.Context;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RelativeLayout.LayoutParams;

public class GridAdapter extends BaseAdapter{
	/// Tag for logging
	private static final String TAG = "PuzzleActivity";
	private SwapPuzzle mContext;
	
	int mGalleryItemBackground;
	//PuzzleLogic mPuzzle= new PuzzleLogic(mContext);

	public GridAdapter(Context con) {
		mContext= (SwapPuzzle)con;


	}

	@Override
	public int getCount() {
		return mContext.mPuzzleLogic.mBmpPieces.length;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		ImageView iView;
		
		if (arg1 == null) {  // if it's not recycled, initialize some attributes

			iView = new ImageView(mContext);
			//Display display = ((WindowManager) mContext.getSystemService(mContext.WINDOW_SERVICE)).getDefaultDisplay();
			//int imageWidth=(int) display.getWidth() / 3;
			//int imageHeight=(int) ((display.getHeight() /3) * 0.5);
			//iView.setLayoutParams(new GridView.LayoutParams(imageWidth,imageHeight));
			//iView.setMaxHeight(imageHeight);
			//iView.setMaxWidth(imageWidth);
			iView.setAdjustViewBounds(true);
			//iView.setLayoutParams(new GridView.LayoutParams(GridView.LayoutParams.WRAP_CONTENT,GridView.LayoutParams.WRAP_CONTENT));
			
			int index= mContext.mPuzzleLogic.mGalleryList.get(arg0);
			//int index= PuzzleLogic.mGalleryList.get(arg0);
			//Log.v(TAG,"index value = " + index );
			iView.setImageBitmap( mContext.mPuzzleLogic.mBmpPieces[index]);
			iView.setTag(index);
			


		}
		
		else {
			iView = (ImageView) arg1;

		}
		
		return iView;
		

	}

}
